home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / gui / protocols / jabbergui.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-13  |  17KB  |  383 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. import wx
  5. from wx import ALL, TOP, BOTTOM, ALIGN_CENTER, EXPAND, VERTICAL, HORIZONTAL, BoxSizer
  6. from gui.toolbox import GetTextFromUser, wx_prop, build_button_sizer, persist_window_pos, snap_pref
  7. from gui.validators import LengthLimit
  8. from common import profile
  9. from util import Storage as S, Delegate
  10. from logging import getLogger
  11. log = getLogger('jabbergui')
  12.  
  13. def set_priority(jabber, set):
  14.     val = GetTextFromUser(_('Enter a priority for %s:' % jabber.username), caption = _('Set Jabber Priority'), default_value = str(jabber.priority))
  15.     if val is not None:
  16.         
  17.         try:
  18.             set(int(val))
  19.         except ValueError:
  20.             pass
  21.         except:
  22.             None<EXCEPTION MATCH>ValueError
  23.         
  24.  
  25.     None<EXCEPTION MATCH>ValueError
  26.  
  27.  
  28. class JabberDeleteConfirmBox(wx.Dialog):
  29.     
  30.     def __init__(self, acct, msg, *a, **k):
  31.         self.acct = acct
  32.         wx.Dialog.__init__(self, *a, **k)
  33.         self.init_components(msg)
  34.         self.bind_events()
  35.         self.layout_components()
  36.         self.del_check.Enable(self.acct.connection is not None)
  37.         self.Layout()
  38.         self.Sizer.Fit(self)
  39.  
  40.     
  41.     def init_components(self, msg):
  42.         self.help_bmp = wx.StaticBitmap(self)
  43.         self.help_bmp.SetBitmap(wx.ArtProvider.GetBitmap(wx.ART_HELP, wx.ART_OTHER, (32, 32)))
  44.         self.msg_label = wx.StaticText(self, label = msg)
  45.         self.del_check = wx.CheckBox(self, label = 'Also delete from Jabber server')
  46.         self.pw_text = wx.TextCtrl(self, style = wx.TE_PASSWORD, validator = LengthLimit(1024))
  47.         self.pw_label = wx.StaticText(self, label = 'Password: ')
  48.         self.yes_btn = wx.Button(self, wx.ID_YES)
  49.         self.yes_btn.SetDefault()
  50.         self.no_btn = wx.Button(self, wx.ID_NO)
  51.         self.del_label = wx.StaticText(self, label = 'Deleting...')
  52.         self.del_label.Show(False)
  53.         self.del_label.Enable(False)
  54.         self.info_sizer = BoxSizer(HORIZONTAL)
  55.         self.btn_sizer = BoxSizer(HORIZONTAL)
  56.         self.pw_sizer = BoxSizer(HORIZONTAL)
  57.         self.delpw_sizer = BoxSizer(VERTICAL)
  58.         self.in_sizer = BoxSizer(HORIZONTAL)
  59.         self.main_sizer = BoxSizer(VERTICAL)
  60.         self.Sizer = BoxSizer(HORIZONTAL)
  61.  
  62.     
  63.     def bind_events(self):
  64.         self.yes_btn.Bind(wx.EVT_BUTTON, self.yes_clicked)
  65.         self.no_btn.Bind(wx.EVT_BUTTON, self.no_clicked)
  66.         self.del_check.Bind(wx.EVT_CHECKBOX, self.on_check)
  67.         self.on_check(None)
  68.  
  69.     
  70.     def layout_components(self):
  71.         self.pw_sizer.Add(int(self.del_check.Size.height * 1.5), 0, wx.ALL, 3)
  72.         self.pw_sizer.Add(self.pw_label, 0, ALL, 3)
  73.         self.pw_sizer.Add(self.pw_text, 0, ALL, 3)
  74.         self.btn_sizer.AddMany([
  75.             (self.yes_btn, 0, ALL, 3),
  76.             (self.no_btn, 0, ALL, 3),
  77.             (self.del_label, 0, ALL, 3)])
  78.         self.in_sizer.AddSpacer(self.help_bmp.Size.width)
  79.         self.delpw_sizer.Add(self.del_check, 0, ALL)
  80.         self.delpw_sizer.Add(self.pw_sizer, 0, ALL, 3)
  81.         self.in_sizer.Add(self.delpw_sizer, 0, ALL, 3)
  82.         self.info_sizer.Add(self.help_bmp, 0, TOP | BOTTOM | ALIGN_CENTER, 3)
  83.         self.info_sizer.Add(self.msg_label, 0, ALL | ALIGN_CENTER, 3)
  84.         self.main_sizer.AddMany([
  85.             (self.info_sizer, 0, ALL, 3),
  86.             (self.in_sizer, 0, ALL, 3),
  87.             (self.btn_sizer, 0, ALIGN_CENTER | ALL, 3)])
  88.         self.Sizer = self.main_sizer
  89.  
  90.     
  91.     def yes_clicked(self, e):
  92.         
  93.         success = lambda : self.EndModal(wx.ID_YES)
  94.  
  95.     
  96.     def show_buttons(self, val = True):
  97.         self.yes_btn.Enabled = val
  98.         self.no_btn.Enabled = val
  99.         self.yes_btn.Show(val)
  100.         self.no_btn.Show(val)
  101.         self.del_label.Show(not val)
  102.         self.Layout()
  103.  
  104.     
  105.     def no_clicked(self, e):
  106.         self.EndModal(wx.NO)
  107.  
  108.     
  109.     def on_check(self, e):
  110.         self.pw_text.Enabled = self.delete
  111.  
  112.     delete = wx_prop('del_check')
  113.     password = wx_prop('pw_text')
  114.  
  115.  
  116. class PasswordChangeDialog(wx.Dialog):
  117.     
  118.     def __init__(self, parent, acct, *a, **k):
  119.         self.acct = acct
  120.         wx.Dialog.__init__(self, parent, title = _('Change Password'), *a, **k)
  121.         self.init_components()
  122.         self.bind_events()
  123.         self.layout_components()
  124.         self.Layout()
  125.         self.Sizer.Fit(self)
  126.  
  127.     
  128.     def init_components(self):
  129.         self.old_pw_label = wx.StaticText(self, label = _('Old Password: '))
  130.         self.old_pw_text = wx.TextCtrl(self, style = wx.TE_PASSWORD, validator = LengthLimit(1024))
  131.         self.new1_pw_label = wx.StaticText(self, label = _('New Password: '))
  132.         self.new1_pw_text = wx.TextCtrl(self, style = wx.TE_PASSWORD, validator = LengthLimit(1024))
  133.         self.new2_pw_label = wx.StaticText(self, label = _('Confirm New Password: '))
  134.         self.new2_pw_text = wx.TextCtrl(self, style = wx.TE_PASSWORD, validator = LengthLimit(1024))
  135.         self.ok_btn = wx.Button(self, wx.ID_OK)
  136.         self.ok_btn.Enable(False)
  137.         self.ok_btn.SetDefault()
  138.         self.cancel_btn = wx.Button(self, wx.ID_CANCEL)
  139.         self.old_sizer = BoxSizer(HORIZONTAL)
  140.         self.new1_sizer = BoxSizer(HORIZONTAL)
  141.         self.new2_sizer = BoxSizer(HORIZONTAL)
  142.         self.btn_sizer = build_button_sizer(self.ok_btn, self.cancel_btn, 2)
  143.         self.main_sizer = BoxSizer(VERTICAL)
  144.         self.Sizer = BoxSizer(HORIZONTAL)
  145.  
  146.     
  147.     def bind_events(self):
  148.         self.old_pw_text.Bind(wx.EVT_TEXT, self.check_fields)
  149.         self.new1_pw_text.Bind(wx.EVT_TEXT, self.check_fields)
  150.         self.new2_pw_text.Bind(wx.EVT_TEXT, self.check_fields)
  151.         self.cancel_btn.Bind(wx.EVT_BUTTON, self.cancel_clicked)
  152.         self.ok_btn.Bind(wx.EVT_BUTTON, self.ok_clicked)
  153.  
  154.     
  155.     def check_fields(self, e):
  156.         old = self.old_password
  157.         new1 = self.new1_password
  158.         new2 = self.new2_password
  159.         if all([
  160.             old,
  161.             new1,
  162.             new2]):
  163.             pass
  164.         self.ok_btn.Enable(new1 == new2)
  165.  
  166.     
  167.     def layout_components(self):
  168.         border = (0, ALL, 2)
  169.         self.old_sizer.Add(self.old_pw_label, *border)
  170.         self.old_sizer.AddStretchSpacer()
  171.         self.old_sizer.Add(self.old_pw_text, *border)
  172.         self.new1_sizer.Add(self.new1_pw_label, *border)
  173.         self.new1_sizer.AddStretchSpacer()
  174.         self.new1_sizer.Add(self.new1_pw_text, *border)
  175.         self.new2_sizer.Add(self.new2_pw_label, *border)
  176.         self.new2_sizer.AddStretchSpacer()
  177.         self.new2_sizer.Add(self.new2_pw_text, *border)
  178.         self.main_sizer.AddMany([
  179.             (self.old_sizer, 0, ALL | EXPAND, 2),
  180.             (self.new1_sizer, 0, ALL | EXPAND, 2),
  181.             (self.new2_sizer, 0, ALL | EXPAND, 2),
  182.             (self.btn_sizer, 0, ALIGN_CENTER | ALL, 2)])
  183.         self.Sizer = self.main_sizer
  184.  
  185.     old_password = wx_prop('old_pw_text')
  186.     new1_password = wx_prop('new1_pw_text')
  187.     new2_password = wx_prop('new2_pw_text')
  188.     
  189.     def cancel_clicked(self, e):
  190.         self.EndModal(wx.ID_CANCEL)
  191.  
  192.     
  193.     def ok_clicked(self, e):
  194.         self.ok_btn.Disable()
  195.         if self.acct.password != self.old_password:
  196.             wx.MessageBox(_('Incorrect Old Password'), _('Incorrect Old Password'))
  197.         elif self.new1_password != self.new2_password:
  198.             wx.MessageBox(_('Passwords do not match'), _('Paswords do not match'))
  199.         else:
  200.             
  201.             def success(st = (None,)):
  202.                 print 'success!', st
  203.                 print 'setting password in', self.acct
  204.                 profile = profile
  205.                 import common
  206.                 self.acct.password = profile.crypt_pw(self.new1_password)
  207.                 for acct in profile.account_manager.accounts:
  208.                     if acct.name == self.acct.username and acct.protocol == self.acct.protocol:
  209.                         acct.update_info(password = profile.crypt_pw(self.new1_password))
  210.                         break
  211.                         continue
  212.                 
  213.                 self.EndModal(wx.ID_OK)
  214.  
  215.             
  216.             def error(self, e = None):
  217.                 print 'error', e
  218.                 self.EndModal(wx.ID_OK)
  219.  
  220.             self.acct.change_password(self.new1_password, success = success, error = error)
  221.  
  222.     
  223.     def Prompt(self, callback):
  224.         self.ShowModal()
  225.  
  226.  
  227.  
  228. def serialize_xmlnode(node):
  229.     return node.serialize(encoding = 'utf-8', format = True).decode('utf-8')
  230.  
  231.  
  232. class XMLConsole(wx.Panel):
  233.     separator_text = '\n\n'
  234.     
  235.     def __init__(self, parent, jabber):
  236.         wx.Panel.__init__(self, parent)
  237.         self.enabled = True
  238.         self.scroll_lock = False
  239.         self.intercept = JabberXMLIntercept(jabber)
  240.         (self.intercept.on_incoming_node,) += (lambda node: self.on_node(node, 'incoming'))
  241.         (self.intercept.on_outgoing_node,) += (lambda node: self.on_node(node, 'outgoing'))
  242.         self.construct()
  243.         self.bind_events()
  244.         self.layout()
  245.  
  246.     
  247.     def Connection(self):
  248.         return self.intercept.jabber
  249.  
  250.     Connection = property(Connection)
  251.     
  252.     def construct(self):
  253.         self.console = wx.TextCtrl(self, -1, style = wx.TE_RICH2 | wx.TE_MULTILINE)
  254.         self.enabled_cb = wx.CheckBox(self, -1, _('&Enabled'))
  255.         self.enabled_cb.SetValue(self.enabled)
  256.         self.scroll_lock_cb = wx.CheckBox(self, -1, _('&Scroll Lock'))
  257.         self.scroll_lock_cb.SetValue(self.scroll_lock)
  258.         self.scroll_lock_cb.Enable(False)
  259.         self.buttons = S(clear_b = wx.Button(self, -1, _('C&lear')), close = wx.Button(self, -1, _('&Close')))
  260.         self.font_colors = dict(incoming = wx.BLUE, outgoing = wx.RED)
  261.  
  262.     
  263.     def bind_events(self):
  264.         self.enabled_cb.Bind((wx.EVT_CHECKBOX,), (lambda e: setattr(self, 'enabled', e.Checked())))
  265.         self.scroll_lock_cb.Bind((wx.EVT_CHECKBOX,), (lambda e: setattr(self, 'scroll_lock', e.Checked())))
  266.         self.buttons.clear_b.Bind((wx.EVT_BUTTON,), (lambda e: self.console.Clear()))
  267.         self.buttons.close.Bind((wx.EVT_BUTTON,), (lambda e: self.Top.Destroy()))
  268.  
  269.     
  270.     def layout(self):
  271.         self.Sizer = s = wx.BoxSizer(wx.VERTICAL)
  272.         s.Add(self.console, 1, wx.EXPAND | wx.ALL, 7)
  273.         button_sizer = wx.BoxSizer(wx.HORIZONTAL)
  274.         button_sizer.Add(self.enabled_cb, 0, wx.LEFT | wx.ALIGN_CENTER_VERTICAL, 7)
  275.         button_sizer.AddStretchSpacer(1)
  276.         button_sizer.AddMany([
  277.             (self.scroll_lock_cb, 0, wx.RIGHT | wx.ALIGN_CENTER_VERTICAL, 7),
  278.             (self.buttons.clear_b, 0, wx.RIGHT, 7),
  279.             (self.buttons.close, 0, wx.RIGHT, 7)])
  280.         s.Add(button_sizer, 0, wx.EXPAND | wx.BOTTOM, 7)
  281.  
  282.     
  283.     def on_check(self, e):
  284.         self.enabled = e.Checked()
  285.  
  286.     
  287.     def on_close(self, e):
  288.         self.intercept.close()
  289.         self.Top.Destroy()
  290.  
  291.     
  292.     def on_node(self, node, node_type):
  293.         if self.enabled:
  294.             wx.CallAfter(self.on_node_gui, serialize_xmlnode(node), node_type)
  295.         
  296.  
  297.     
  298.     def on_node_gui(self, node_text, node_type):
  299.         console = self.console
  300.         style = console.GetDefaultStyle()
  301.         style.SetTextColour(self.font_colors[node_type])
  302.         start = end = console.GetLastPosition()
  303.         console.SetStyle(start, end, style)
  304.         if self.scroll_lock:
  305.             vpos = console.GetScrollPos(wx.VERTICAL)
  306.         
  307.         console.AppendText(self.separator_text + node_text)
  308.         if self.scroll_lock:
  309.             console.SetScrollPos(wx.VERTICAL, vpos, True)
  310.         
  311.  
  312.  
  313.  
  314. class XMLConsoleFrame(wx.Frame):
  315.     
  316.     def __init__(self, connection):
  317.         wx.Frame.__init__(self, None, -1, _('XML Console for %s') % connection.username, name = 'XML Console')
  318.         self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
  319.         self.panel = XMLConsole(self, connection)
  320.         self.Bind(wx.EVT_CLOSE, self.panel.on_close)
  321.         self.Sizer = wx.BoxSizer(wx.VERTICAL)
  322.         self.Sizer.Add(self.panel, 1, wx.EXPAND | wx.ALL)
  323.         persist_window_pos(self, nostack = True)
  324.         snap_pref(self)
  325.  
  326.  
  327.  
  328. def show_xml_console(connection):
  329.     for win in wx.GetTopLevelWindows():
  330.         if isinstance(win, XMLConsoleFrame) and win.panel.Connection is connection:
  331.             log.info('raising existing xml console: %r', win)
  332.             win.Raise()
  333.             return win
  334.             continue
  335.     
  336.     frame = XMLConsoleFrame(connection)
  337.     log.info('created new xml console: %r', frame)
  338.     frame.Show()
  339.     return frame
  340.  
  341.  
  342. class JabberXMLIntercept(object):
  343.     
  344.     def __init__(self, jabber):
  345.         self.jabber = jabber
  346.         self.on_incoming_node = Delegate()
  347.         self.on_outgoing_node = Delegate()
  348.         jabber.add_observer(self.state_changed, 'state')
  349.         self.state_changed(jabber)
  350.  
  351.     
  352.     def close(self):
  353.         self.jabber.remove_observer(self.state_changed, 'state')
  354.         stream = self.jabber.stream
  355.         if stream is not None:
  356.             self.disconnect(stream)
  357.         
  358.         del self.on_incoming_node[:]
  359.         del self.on_outgoing_node[:]
  360.  
  361.     
  362.     def state_changed(self, jabber, *a):
  363.         if jabber.state == jabber.Statuses.ONLINE:
  364.             stream = jabber.stream
  365.             if stream is None:
  366.                 log.warning('jabber is online but has no stream')
  367.             else:
  368.                 self.connect(stream)
  369.         else:
  370.             self.disconnect(stream)
  371.  
  372.     
  373.     def connect(self, stream):
  374.         stream.on_incoming_node.add_unique(self.on_incoming_node)
  375.         stream.on_outgoing_node.add_unique(self.on_outgoing_node)
  376.  
  377.     
  378.     def disconnect(self, stream):
  379.         stream.on_incoming_node.remove_maybe(self.on_incoming_node)
  380.         stream.on_outgoing_node.remove_maybe(self.on_outgoing_node)
  381.  
  382.  
  383.